<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	Class.forName("com.mysql.jdbc.Driver");
	Connection con = null;
	Statement smt = null;
	ResultSet rst = null;
	request.setCharacterEncoding("UTF-8");
	String email = request.getParameter("email");
	String name = request.getParameter("name");
	String question = request.getParameter("question");
	String time = new java.util.Date().toString();
	String SQL = null;
	int i = 0;
	if (email.length() == 0 || name.length() == 0 || question.length() == 0) response.sendRedirect("help.jsp?fail=true");
	else
	try {
		String username = "root";
		String password = "";
		String url = "jdbc:mysql://127.0.0.1:3306/banhang?useUnicode=true&characterEncoding=UTF-8";
		con = DriverManager.getConnection(url, username, password);
		System.out.println("Da ket noi CSDL");
		smt = con.createStatement();
		rst = smt.executeQuery("select * from question");
		while (rst.next()) {
			i++;
		}
		SQL = "INSERT INTO question VALUES ('"+i+"', '"+email+"', '"+name+"', '"+question+"')";
		smt.execute(SQL);
		con.close();
		System.out.println("Dong ket noi");
		response.sendRedirect("help.jsp");
	}
	catch (Exception e) {
		e.printStackTrace();
		System.out.println("KHONG KET NOI DUOC");
	}
%>
</body>
</html>